package com.example.base.mvvm

import androidx.lifecycle.ViewModel
import com.example.base.net.ApiServer
import com.example.base.net.RetrofitUtils
import com.google.gson.Gson
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody

open class BaseViewModel :ViewModel(){

    val apiServer = RetrofitUtils.getRetrofit().create(ApiServer::class.java)

    //因为在实际调用经常使用body的参数，所有提出公共部分
    fun mapToBody(map:Map<String,Any>):RequestBody{
        val json = Gson().toJson(map)
        val body = RequestBody.create("application/json;charset=utf-8".toMediaType(),json)
        return body
    }
}